<script setup lang="ts">
import { getBannerList } from "../../api/epi";
import { ref, onMounted } from "vue";
import { getDesc, getAsc } from "../../api/epi";

const bannerList = ref([]);
const getBanners = async () => {
  let res = await getBannerList();
  bannerList.value = res.data;
  console.log(res, "bannerList");
};
const seList = ref(["升序", "倒序", "默认"]);
const selStr = ref<string>("");
const selChang = async (val: any) => {
  if (val == "升序") {
    let res = await getAsc();
    console.log(res);

    bannerList.value = res.data;
  } else if (val == "倒序") {
    let res = await getDesc();
    console.log(res);

    bannerList.value = res.data;
  } else {
    getBanners();
  }
};
onMounted(() => {
  getBanners();
});
</script>
<template>
  <div class="box">
    <el-select
      v-model="selStr"
      class="m-2"
      placeholder="感染人数排序"
      @change="selChang"
    >
      <el-option
        v-for="(item, i) in seList"
        :key="i"
        :label="item"
        :value="item"
      />
    </el-select>
    <h2>各地疫情情况</h2>
    <el-table :data="bannerList" stripe>
      <el-table-column label="城市">
        <template #default="scoped">
          <span>{{ scoped.row.place }}</span>
        </template>
      </el-table-column>
      <el-table-column label="感染人数">
        <template #default="scoped">
          <span>{{ scoped.row.infect }}</span>
        </template>
      </el-table-column>
      <el-table-column label="治愈人数">
        <template #default="scoped">
          <span>{{ scoped.row.cure }}</span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<style lang="scss" scoped>
.box {
  width: 100%;
  // display: flex;
  // flex-direction: column;
  // align-items: center;
  margin-top: 20px;
}
.inBox {
  display: flex;
  .table {
    width: 540px;
  }
}
</style>
